package org.opens.publisher.impl;

import org.opens.event.StudentEvent;
import org.opens.publisher.StudentPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
public class StudentPublisherImpl implements StudentPublisher {

    /**
     * spring提供的事件驱动类, 可以使用这个类来发布事件
     */
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void publish() {
        StudentEvent studentEvent = new StudentEvent(this);
        studentEvent.setName("属性name");
        studentEvent.setMessage("属性message");
        // 发布事件
        applicationEventPublisher.publishEvent(studentEvent);
    }

}
